package util;

public class UnorderedPair<V extends Comparable>
{
  public final V v1, v2;

  public UnorderedPair(V v1, V v2)
  {
    if (v1.compareTo(v2) > 0) {
      this.v1 = v2;
      this.v2 = v1;
    } else {
      this.v1 = v1;
      this.v2 = v2;
    }
  }

  @Override
  public boolean equals(Object obj)
  {
    if (obj instanceof UnorderedPair) {
      UnorderedPair pair = (UnorderedPair)obj;
      if (pair.v1.equals(v1) && pair.v2.equals(v2)) {
        return true;
      }
    }
    return false;
  }

  @Override
  public int hashCode()
  {
    int hash = 5;
    hash = 71 * hash + (this.v1 != null ? this.v1.hashCode() : 0);
    hash = 71 * hash + (this.v2 != null ? this.v2.hashCode() : 0);
    return hash;
  }

  @Override
  public String toString()
  {
    return "{" + v1.toString() + ", " + v2.toString() + "}";
  }

  public V getV1()
  {
    return v1;
  }

  public V getV2()
  {
    return v2;
  }

}
